package control;

import javafx.application.Application;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Slider;
import javafx.scene.text.Text;

// 滑动条(比滚动条多了标签与刻度,不能用滑轮滚动)
public class SliderDemo extends Application {
	private BorderPane root = new BorderPane();
	private Pane pane = new Pane();
	private Text text;
	private Slider slider;
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
    public void start(Stage stage) {
	   
	   text = new Text(30, 30, "javafx is cool");        
	   pane.getChildren().add(text);
	   root.setCenter(pane);
	   
	   // 水平滑动条
	   slider = new Slider(0, 100, 50);
	   slider.setShowTickLabels(true);	// 显示标签
	   slider.setShowTickMarks(true);	// 显示刻度
	   slider.setMajorTickUnit(20);		// 设置大刻度为20	
//	   slider.setValue(20);				// 设置当前位置
//	   slider.setOrientation(Orientation.VERTICAL);		设置方向为竖直
	   root.setBottom(slider);	
	   
	   Scene scene = new Scene(root, 300, 300);
	   stage.setScene(scene);
	   stage.setTitle("Slider");
	   stage.show();
	   
	   // 监听器
	   slider.valueProperty().addListener(e -> {
		   double scale = root.getWidth()/slider.getMax();	// 获取比例
		   text.setX(slider.getValue()*scale);      
	   });
    }
}


